package com.xs.exception;

import com.alibaba.fastjson.JSONObject;
import com.xs.common.R;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

import java.rmi.ServerException;

/**
 * @author 徐双
 * @ClassName MyExceptionHandler
 * @date 2022-11-28 11:02
 * @Description:
 * @Version:1.0
 */

@ControllerAdvice
public class MyExceptionHandler {
    /**
     * 如果抛出的是ServiceException，则 调用该方法
     * @Param se 业务异常
     *
     */
    @ExceptionHandler(Exception.class)
    @ResponseBody
    public Object handleException(Exception e){
        String msg = e.getMessage();
        if (msg == null || msg.equals("")){
            msg = "服务器出错";
        }
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("code", 1000);
        jsonObject.put("message", msg);
        return jsonObject;



    }
}
